
import os

import ament_index_python.packages
import launch
import launch_ros.actions

import yaml


def generate_launch_description():
    share_dir = ament_index_python.packages.get_package_share_directory('to_pointcloud')
    params_file = os.path.join(share_dir, 'config', 'qs176_cloud_params.yaml')
    with open(params_file, 'r') as f:
        params = yaml.safe_load(f)['to_pointcloud_node']['ros__parameters']
        params['calibration'] = os.path.join(share_dir, 'params', 'CZLidar_QS88_8.yaml')
        to_pointcloud_node = launch_ros.actions.Node(package='to_pointcloud',
        executable='to_pointcloud_node',
        output='both',
        parameters=[params])

        return launch.LaunchDescription([to_pointcloud_node,
    launch.actions.RegisterEventHandler(
    event_handler=launch.event_handlers.OnProcessExit(
    target_action=to_pointcloud_node,
    on_exit=[launch.actions.EmitEvent(
    event=launch.events.Shutdown())],
    )),
    ])
